fix(memory_pool): add thread safety, overflow checks, and double-free protection #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
pthread_mutexto protect all public functions for thread safetynode_sizetomax_align_tfor proper memory alignmentmemory_pool_check_node()memory_pool_free()Changes
Thread Safety
pthread_mutex_t mutextoMEMORY_POOLstructmemory_pool_init(), destroy inmemory_pool_cleanup()memory_pool_alloc()andmemory_pool_free()Integer Overflow Protection
node_count_per_chunk > SIZE_MAX / node_sizebefore multiplication inmemory_pool_add_chunk()Double-Free Detection
MEMORY_POOL_MAGIC_ALLOCATEDandMEMORY_POOL_MAGIC_FREEmemory_pool_free()to detect double-free attemptsMemory Alignment
align_size()helper function to alignnode_sizetomax_align_tBug Fixes
memory_pool_check_node()log messagep_nodeparameter inmemory_pool_free()Test Plan
🤖 Generated with Claude Code